
class Hero():

    def __init__(self, name, hp):
        self.name = name
        self.hp = hp
        self.level = 1
        self.__money = 500

    def kill_other_hero(self):
        print("【{}】击败了其他英雄。。。".format(self.name))
        self.level += 1
        self.__money += 300

    def func1(self):
        print("方法1")

    def func2(self):
        print("方法2")

def func():
    print("这是修改后的方法。。。。")

# gailun = Hero("盖伦", 1800)
# 获取对象的属性
# print(gailun.name)
# print(getattr(gailun, 'hp'))
# while True:
#     value = input("请输入你想获取的对象属性是什么：")
#     print(getattr(gailun, value))
# 获取对象的方法
# gailun.kill_other_hero()
# getattr(gailun, "kill_other_hero")()
# while True:
#     value = input("请输入你想执行的对象方法是什么：")
#     if hasattr(gailun, value):
#         getattr(gailun, value)()  # 判断对象是否有对应的属性及方法,返回True或False
#     else:
#         print("对象没有定义此方法/属性")
gailun = Hero("盖伦", 1800)
# print(gailun.name)
# delattr(gailun, "name")       # # 删除指定的属性
# del gailun.name
# setattr(gailun, 'name', "盖伦1")
# gailun.name = '盖伦1'  	# 修改属性的值
# print(gailun.name)
gailun.kill_other_hero()
setattr(gailun, 'kill_other_hero', func)
print("--------------------------------------------------")
gailun.kill_other_hero()